package com.chenzhiling.fs.objectStorage;

import org.apache.hadoop.fs.Path;

import java.io.IOException;

/**
 * @Author: CHEN ZHI LING
 * @Date: 2021/10/8
 * @Description: 工具类
 */
public class CephObjectUtil {

    public static CephObjectAttributes getCephFiLeByPath(Path path) throws IOException {
        if (null == path){
            throw new IOException("path is null");
        }
        String s = path.toString();
        if (!"ceph://".equals(s.substring(0,7))){
            throw new IOException("请输入正确的uri地址 ceph://bucketName/objectName");
        }
        String[] cephPath = s.split("//");
        String movePrefix = cephPath[1];
        //分割桶名和对象名
        String[] bucketAndObject = movePrefix.split("/");
        if (1 == bucketAndObject.length){
            return new CephObjectAttributes(bucketAndObject[0],null);
        }
        //获得桶名
        String bucketName = bucketAndObject[0];
        //获得对象名
        String objectName = movePrefix.substring(bucketName.length()+1);
        return new CephObjectAttributes(bucketName, objectName);
    }
}
